package com.juanpi.order.runner;

import com.alibaba.fastjson.JSONObject;
import com.juanpi.order.common.utils.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author xueqing
 *         Created on 2017/1/6.
 */
@Service
public class PushHttpClient {

//    @Autowired
//    private LogServcie logServcie;

    private static Logger logger = LoggerFactory.getLogger(PushHttpClient.class);
    private static final String RETURN_CODE = "return_code";
    private static final String SUCCESS_CODE = "success";
    public boolean pushBody(String url,String body,Map<String,String> header){
        try {

            String result = HttpClientUtil.doPost(url, body, header);
            logger.info("result.........." + result);
            JSONObject resultData = JSONObject.parseObject(result);
            String resultCode = resultData.getString(RETURN_CODE);

            if(resultCode.equalsIgnoreCase(SUCCESS_CODE)){
//                logServcie.addLog(url,LogServcie.NORMAL,"");
                return true;
            } else {
//                logServcie.addLog(url,LogServcie.FAULT,resultCode);
                return false;
            }
        } catch (Exception e) {
            logger.error("result.........."+e);
//            logServcie.addLog(url,LogServcie.FAULT,e.getMessage());
            return false;
        }
    }
}